
<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="../../favicon.ico">

    <title>Signin Template for Bootstrap</title>

    <!-- Bootstrap core CSS -->
    <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
	<link href="../static/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <link href="https://v3.bootcss.com/assets/css/ie10-viewport-bug-workaround.css" rel="stylesheet">

    
    <!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
    <!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
    <script src="https://v3.bootcss.com/assets/js/ie-emulation-modes-warning.js"></script>

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="https://cdn.bootcss.com/html5shiv/3.7.3/html5shiv.min.js"></script>
      <script src="https://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>

  <body>
	
    <div class="container">
    <ul class="nav nav-pills">
     
	  <li role="presentation" ><a href="/">首页</a></li>
	  <li role="presentation" ><a href="/orders/ordersInfo">未提交订单</a></li>
	  <li role="presentation" class="active"><a href="/orders/ordersList">订单列表</a></li>
	  <li role="presentation"><a href="/hello/out">退 出</a></li>
	</ul>
    	<h2>用户名:${username}</h2>
    	<div class=table-responsive">
		<table id="tb_departments" class="table text-nowrap"></table></div>
    </div> <!-- /container -->
	
</body>
	<!-- Bootstrap core JavaScript
	================================================== -->
	<!-- Placed at the end of the document so the pages load faster -->
	<script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
	<script>window.jQuery || document.write('<script src="../static/js/jquery.min.js"><\/script>')</script>
	<script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"></script>
	<script src="../static/bootstrap-table/bootstrap-table.min.js"></script>
	<script src="../static/bootstrap-table/locale/bootstrap-table-zh-CN.js"></script>
    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <script src="https://v3.bootcss.com/assets/js/ie10-viewport-bug-workaround.js"></script>
    <script>
    $(function () {

        //1.初始化Table
        var oTable = new TableInit();
        oTable.Init();

        //2.初始化Button的点击事件
        var oButtonInit = new ButtonInit();
        oButtonInit.Init();

    });
    
 // 修改按钮、删除按钮
    function addFunctionAlty(value, row, index) {
        return [
            '<button type="button" id="btn_edit" class="btn btn-default">订单详情</button>  ',
            //'<button id="btn_delete" class="btn btn-warning">删除</button>'
        ].join('');
    }
    window.operateEvents = {
    		 
    	    // 点击修改按钮执行的方法
    	    'click #btn_edit': function (e, value, row, index) {
    	       // 写自己的方法。。。
    	       console.info(row);
    	       var orderId = row.id;
    	       doOrders(orderId);
    	       
    	    },
    	    // 点击删除按钮执行的方法
    	    'click #btn_delete': function (e, value, row, index) {
    	        // 写自己的方法。。。
    	    }
    	};

    var TableInit = function () {
        var oTableInit = new Object();
        //初始化Table
        oTableInit.Init = function () {
            $('#tb_departments').bootstrapTable({
            	url:"/ordersDetail/ordersList",         //请求后台的URL（*）
                method: 'post',                      //请求方式（*）
                //toolbar: '#toolbar',                //工具按钮用哪个容器
                striped: true,                      //是否显示行间隔色
                cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
                pagination: true,                   //是否显示分页（*）
                sortable: false,                     //是否启用排序
                sortOrder: "asc",                   //排序方式
                //queryParams: oTableInit.queryParams,//传递参数（*）
                sidePagination: "client",           //分页方式：client客户端分页，server服务端分页（*）
                pageNumber:1,                       //初始化加载第一页，默认第一页
                pageSize: 5,                       //每页的记录行数（*）
                pageList: [5, 10, 50, 100],        //可供选择的每页的行数（*）
                search: false,                       //是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大
                strictSearch: true,
                showColumns: true,                  //是否显示所有的列
                showRefresh: true,                  //是否显示刷新按钮
                minimumCountColumns: 2,             //最少允许的列数
                clickToSelect: true,                //是否启用点击选中行
                //height: 500,                        //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
                uniqueId: "id",                     //每一行的唯一标识，一般为主键列
                showToggle:true,                    //是否显示详细视图和列表视图的切换按钮
                cardView: false,                    //是否显示详细视图
                detailView: false,                   //是否显示父子表
                columns: [
                
                {
                    field: 'id',
                    title: '订单ID'
                }, {
                    field: 'orderAmount',
                    title: '订单金额'
                }, {
                    field: 'status',
                    title: '状态',
                    formatter : function (value, row, index) {
                        console.info(row);
                    	if (row['status'] == 1) {
                            return '已提交';
                        }
                        if (row['status'] == 2) {
                            return '已作废';
                        }
                        if (row['status'] == 0) {
                            return '未生效';
                        }
                        return value;
                    }
        
                },{
                    field: 'createTime',
                    title: '创建时间'
                }, {
                    field: 'entryTime',
                    title: '确认时间'
                } ,{
                    field: 'operation',
                    title: '操作',
                    align: 'center',
                    events:operateEvents,//给按钮注册事件
                    formatter:addFunctionAlty //表格中增加按钮
                }
     ]
            });
        };

        //得到查询的参数
        oTableInit.queryParams = function (params) {
            var temp = {   //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                limit: params.limit,   //页面大小
                offset: params.offset,  //页码
                departmentname: $("#txt_search_departmentname").val(),
                statu: $("#txt_search_statu").val()
            };
            return temp;
        };
        return oTableInit;
    };


    var ButtonInit = function () {
        var oInit = new Object();
        var postdata = {};

        oInit.Init = function () {
            //初始化页面上面的按钮事件
        };

        return oInit;
    };
    
    
   	function doOrders(orderId) {
   		$("#formTable").bootstrapTable('destroy');
   		/*bootstrap table*/
   		$('#formTable').bootstrapTable({
   			url:"/ordersDetail/orderInfo?orderID="+orderId, //请求数据url
   			showToggle: false,
   		    showHeader : true,
   		    showColumns : false,
   		    showRefresh : false,
   		    pagination: true,//分页
   		    sidePagination : 'client',//服务器端分页
   		    pageNumber : 1,
   		 	pageSize: 5,
   		    pageList: [5, 10],//分页步进值
   		    search: false,//显示搜索框
   		    //表格的列
   		    columns: [
				{
				    field: 'id',
				    title: 'ID'
				}, {
				    field: 'goodsId',
				    title: '商品ID'
				}, {
				    field: 'price',
				    title: '单价'
				}, {
				    field: 'number',
				    title: '数量'
				}, 
   		    ]
   		});
   		$("#ModalInfo").modal("show");
   		
   	}


   	
    </script>
  	<!-- 模态框（Modal） -->
	<div class="modal fade" id="ModalInfo" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	    <div class="modal-dialog">
	        <div class="modal-content">
	            <div class="modal-header">
	                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
	                <h4 class="modal-title" id="myModalLabel">订单详情</h4>
	            </div>
	            <div class="modal-body">
	            	
	            	<table id="formTable" class="table text-nowrap">
	            	  
					</table>
	            </div>
	            <div class="modal-footer">
	                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
	            </div>
	        </div><!-- /.modal-content -->
	    </div><!-- /.modal -->
	</div>
</html>
